<template>
  <div class="app-container">
    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">

      <el-col :span="6">
        <el-form-item label="额度申请:" prop="orderNo">
          <el-input v-model="queryParams.orderNo" clearable placeholder="请输入额度申请编号"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="客户名称:" prop="customerName">
          <el-input v-model="queryParams.customerName" clearable placeholder="请输入客户名称"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="信审状态:" prop="creditReviewStatus">
          <el-select v-model="queryParams.creditReviewStatus" clearable>
            <el-option v-for="dict in dict.type.credit_review_apply_status" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>


      <el-col :span="6">
        <el-form-item label="产品方案:" prop="planName">
          <el-input v-model="queryParams.planName" clearable placeholder="请输入产品方案"></el-input>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="创建时间:">
          <el-date-picker v-model="timeRange" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
                          @change="changeCreateTime"></el-date-picker>
        </el-form-item>
      </el-col>

      <el-col :span="6">
        <el-form-item label="是否补充资料:" prop="supplemented" label-width="130px">
          <el-select v-model="queryParams.supplemented" clearable>
            <el-option v-for="dict in dict.type.business_yes_no" :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
          </el-select>
        </el-form-item>
      </el-col>


    </SearchContent>
    <div class="card-wrap paddingAll20" label-width="86px">
      <div class="table-title-wrap justify-end">
        <el-button type="primary" size="mini" @click="handleExport"
                   v-hasPermi="['letterReview:orderApply:export']">导出
        </el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @setSizeCurrent="getList" border>
        <template slot="tableColAc">
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px" fixed="left">
            <template v-slot="{row}">
              <e-button v-hasPermi="['letterReview:orderApply:detail']" size="mini" type="text" @click="handleOperate(99,row)"
              >查看
              </e-button>
              <e-button v-hasPermi="['letterReview:orderApply:commit']" v-if="row.creditReviewStatus==1" size="mini" type="text" @click="handleOperate(1,row)"
              >提交信审
              </e-button>
              <e-button v-hasPermi="['letterReview:orderApply:commit']" v-if="row.creditReviewStatus==2 || row.creditReviewStatus==7" size="mini" type="text"
                        @click="handleOperate(2,row)"
              >重新提交信审
              </e-button>
              <template v-if="row.creditReviewStatus==3">
                <e-button v-hasPermi="['letterReview:orderApply:additionFiles']" v-if="row.supplemented==1" size="mini" type="text" @click="handleOperate(3,row)"
                >补充资料
                </e-button>
                <e-button v-hasPermi="['letterReview:orderApply:cancleOrder']" size="mini" type="text" @click="handleOperate(4,row)"
                >撤单
                </e-button>
              </template>

              <template v-if="(row.creditReviewStatus==5 || row.creditReviewStatus==6)&&row.totalRemainingNumber>0">
                <e-button v-hasPermi="['letterReview:orderApply:voidRemindCreidt']" size="mini" type="text" @click="handleOperate(6,row)"
                >作废剩余额度
                </e-button>
              </template>
            </template>
          </el-table-column>

        </template>
        <template slot="tableCol">
          <el-table-column label="额度申请编号" align="center" prop="orderNo" min-width="180px" show-overflow-tooltip fixed="left">
            <template v-slot="{row}">
              <e-button class="enable-text-select" size="mini" type="text" @click="goQurtaApplyDetail(row)"
              >{{ row.orderNo }}
              </e-button>
            </template>
          </el-table-column>
          <el-table-column label="出租方" align="center" prop="lessor" min-width="120px" show-overflow-tooltip fixed="left"/>
          <el-table-column label="客户名称" align="center" prop="customerName" min-width="120px" show-overflow-tooltip fixed="left"/>
          <el-table-column label="状态" align="center" prop="creditReviewStatus" min-width="120px" show-overflow-tooltip>
            <template v-slot="{row}">
              <dict-tag :options="dict.type.credit_review_apply_status" :value="row.creditReviewStatus"/>
              <el-tag v-if="row.supplemented==1" type="warning">待补充资料</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="申请总台数" align="center" prop="totalApplicationNumber" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="通过台数" align="center" prop="totalPassNumber" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="拒绝台数" align="center" prop="totalRejectNumber" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="产品方案" align="center" prop="planName" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="第一次提交时间" align="center" prop="firstSubmissionTime" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="第一次批复时间" align="center" prop="firstApprovalTime" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="第一次批复建议" align="center" prop="firstApprovalProposal" min-width="120px" show-overflow-tooltip>
            <template v-slot="{row}">
              <dict-tag :options="dict.type.credit_review_status" :value="row.firstApprovalProposal"/>
            </template>
          </el-table-column>
          <el-table-column label="第二次提交时间" align="center" prop="secondSubmissionTime" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="第二次批复时间" align="center" prop="secondApprovalTime" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="第二次批复建议" align="center" prop="secondApprovalProposal" min-width="120px" show-overflow-tooltip>
            <template v-slot="{row}">
              <dict-tag :options="dict.type.credit_review_status" :value="row.secondApprovalProposal"/>
            </template>
          </el-table-column>
          <el-table-column label="客户编号" align="center" prop="customerCode" min-width="120px" show-overflow-tooltip />
          <el-table-column label="额度申请提交人" align="center" prop="submitter" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="创建时间" align="center" prop="createTime" min-width="120px" show-overflow-tooltip/>
          <el-table-column label="信审完成时间" align="center" prop="overTime" min-width="120px" show-overflow-tooltip/>
        </template>
      </table-page>
    </div>
    <replenish-files ref="replenishFiles" @success="handleQuery"></replenish-files>
    <order-void-remaining-balance ref="orderVoidRemainingBalance" @success="handleQuery"></order-void-remaining-balance>
    <canle-order ref="cancleOrder" @success="handleQuery"></canle-order>
  </div>
</template>

<script>
import ReplenishFiles from "@/views/letterReview/order/components/ReplenishFiles.vue";
import OrderVoidRemainingBalance from "@/views/letterReview/order/components/OrderVoidRemainingBalance.vue";
import CanleOrder from "@/views/letterReview/order/components/CanleOrder.vue";
import SearchContent from "@/components/SearchContent/index.vue";
import * as creditApplyApi from "@/api/letterReview/creditReviewApply"

export default {
  components: {
    SearchContent,
    CanleOrder,
    OrderVoidRemainingBalance,
    ReplenishFiles
  },
  name:'LetterReviewOrderList',
  dicts: ['credit_review_apply_status', 'business_yes_no', 'credit_review_status'],
  props: {},
  data() {
    // 这里存放数据
    return {
      // 遮罩层
      loading: false,
      // 查询参数
      timeRange: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        customerName: null,
        creditReviewStatus: null,
        planName: null,
        startTime: null,
        endTime: null,
        supplemented: null,
      },
      total: 0,
      dataList: []
    }
  },
  mounted() {
    this.getList()
  },
  activated() {
    this.getList()
  },
  // 方法集合
  methods: {
    /** 查询信审申请列表 */
    getList() {
      this.loading = true;
      creditApplyApi.creditReviewApplyList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
      }).finally(() => {
        this.loading = false
      })

    },

    changeCreateTime(times) {
      this.queryParams.startTime = times[0]
      this.queryParams.endTime = times[1]
    },
    handleOperate(type, row) {
      switch (type) {
        case 1://提交信审
          this._toPage({
            name: 'AddLetterReview',
            query: {id: row.id, type: 1}
          })
          break
        case 2://重新提交信审
          this._toPage({name: 'EditLetterReview', query: {id: row.id, type: 2, applicationNo: row.applicationNo}})
          break
        case 3://补充资料
          this.$refs.replenishFiles.show(row.applicationNo)
          break
        case 4://撤单
          this.$refs.cancleOrder.show(row.applicationNo)
          break
        case 6://作废剩余额度
          this.$refs.orderVoidRemainingBalance.show(row.applicationNo)
          break
        case 99://信审申请详情
          this._toPage({name: 'CreditApplyDetail', query: {id: row.id}})
          break
      }
    },
    //查看额度申请详情
    goQurtaApplyDetail(row) {
      if (this.checkPermi(['quota:apply:list:look'])) {
        this._toPage({
          name: 'ApplyDetails',
          query: {
            calcSchemeId: row.calcSchemeId
          }
        })
      } else {
        this.$message.warning('无权限')
      }

    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.$nextTick(()=>{
        this.timeRange = []
        this.queryParams.startTime=null
        this.queryParams.endTime=null
        this.$refs?.queryForm?.resetFields();
        this.handleQuery();
      })
    },
    // 导出
    handleExport() {
      this.download('/creditReview/creditReviewApply/export', this.queryParams, `信审申请_${new Date().getTime()}.xlsx`)
    },


  },


}
</script>

<style lang="scss" scoped>
</style>
